<!--
 * @Description:
 * @FilePath: \rs_wms_pc\src\views\invoice\preparation\pickList.vue
-->
<template>
    <div class="app-container">
      <!-- <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['bill:preparationDetail:add']">新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['bill:preparationDetail:edit']">修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['bill:preparationDetail:remove']">删除</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row> -->

      <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange" height="25vh">
        <!-- <el-table-column type="selection" width="55" align="center" /> -->
        <el-table-column label="序号" type="index" width="50" />
        <af-table-column label="单据编号" align="center" prop="no" />
        <af-table-column :label="$t('status')" align="center" prop="orderStatus" >
          <template slot-scope="scope">
            <dict-tag :options="dict.type.invoice_order_status" :value="scope.row.orderStatus"/>
          </template>
        </af-table-column>
        <el-table-column label="已下发工单数量" align="center" prop="distributeQty" min-width="152" />
        <el-table-column label="拣货员" align="center" prop="pickerByName" min-width="152" />
        <el-table-column label="创建时间" align="center" prop="createTime" min-width="152" />
      </el-table>

      <!-- <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" /> -->

      <!-- 添加或修改备料拣货单对话框 -->
      <!-- <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="物料编号" prop="productNo">
            <el-select style="width: 100%" v-model="form.productNo" filterable placeholder="请选择物料编号">
              <el-option
                v-for="dict in productList"
                :key="dict.productNo"
                :label="dict.productNo"
                :value="dict.productNo"
                @click.native="
                  form.productName = dict.productName
                  form.productUnit = dict.company
                "
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="物料名称" prop="productName">
            <el-input v-model="form.productName" :disabled="true" placeholder="请先选择物料编号" />
          </el-form-item>
          <el-form-item label="需求数量" prop="requirementQty">
            <el-input-number v-model="form.requirementQty" placeholder="请输入需求数量" />
          </el-form-item>
          <el-form-item label="单位用量" prop="dosage">
            <el-input-number v-model="form.dosage" placeholder="请输入单位用量" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog> -->
    </div>
  </template>

    <script>
    import { listOrder } from "@/api/inOutStock/outStockOrder";

  export default {
    name: "PreparationDetail",
    inject: ["refresh"],
    dicts: ["invoice_order_status"],
    props: {
      orderData: {},
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 备料拣货单表格数据
        orderList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 0,
          no: null,
          relOrderNo: null,
          productNo: null,
          productName: null,
          productUnit: null,
          totalQty: null,
          outBarcode: null,
          inBarcode: null,
          batchNo: null,
          sort: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          no: [{ required: true, message: "编号不能为空", trigger: "blur" }],
          orderNo: [{ required: true, message: "单据编号不能为空", trigger: "blur" }],
          delFlag: [{ required: true, message: "是否删除：1是 0否不能为空", trigger: "blur" }],
        },
        productList:[]
      }
    },
    watch: {
      // 监视订单信息变动
      orderData(newValue) {
        if (!newValue || !newValue.no) {
          this.queryParams.relOrderNo = ""
        } else {
          this.queryParams.relOrderNo = newValue.no
        }
        this.getList()
      },
    },
    created() {
      this.getList()
    },
    methods: {
      /** 查询备料拣货单列表 */
      getList() {
        this.loading = true

        if (!this.queryParams.relOrderNo) {
          this.orderList = []
          this.total = 0
          this.loading = false
          return
        }
        listOrder(this.queryParams).then((response) => {
          this.orderList = response.rows
          this.total = response.total
          this.loading = false
        })
      },
      // 取消按钮
      cancel() {
        this.open = false
        this.reset()
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          no: null,
          orderNo: null,
          productNo: null,
          productName: null,
          productUnit: null,
          totalQty: null,
          outBarcode: null,
          inBarcode: null,
          batchNo: null,
          sort: null,
          remark: null,
          delFlag: null,
          createBy: null,
          updateBy: null,
          updateTime: null,
          createTime: null,
        }
        this.resetForm("form")
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm")
        this.handleQuery()
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map((item) => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset()
        this.form.relOrderNo = this.orderData&&this.orderData.no?this.orderData.no:''
        this.open = true
        this.title = "添加备料拣货单"
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset()
        const id = row.id || this.ids
        getPreparationDetail(id).then((response) => {
          this.form = response.data
          this.open = true
          this.title = "修改备料拣货单"
        })
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate((valid) => {
          if (valid) {
            if (this.form.id != null) {
              updatePreparationDetail(this.form).then((response) => {
                this.$modal.msgSuccess("修改成功")
                this.open = false
                this.getList()
              })
            } else {
              addPreparationDetail(this.form).then((response) => {
                this.$modal.msgSuccess("新增成功")
                this.open = false
                this.getList()
              })
            }
          }
        })
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids
        this.$modal
          .confirm(this.$t("deleteTip", { num: ids.length }))
          .then(function () {
            return delPreparationDetail(ids)
          })
          .then(() => {
            this.getList()
            this.$modal.msgSuccess("删除成功")
          })
          .catch(() => {})
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download(
          "bill/preparationDetail/export",
          {
            ids: this.ids,
            ...this.queryParams,
          },
          `preparationDetail_${new Date().getTime()}.xlsx`
        )
      },
    },
  }
  </script>
